/**
 * @properties={typeid:35,uuid:"4C33C33B-D483-4C6C-8A95-8C74E7C04C7A"}
 */
var fMesAnio = null;

/**
 * Perform the element default action.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"30B8F438-250B-48E3-9201-B5D10A9321BA"}
 */
function seguir() {
	
	history.removeForm('balance_2')
	solutionModel.removeForm('balance_2')
	if (fMesAnio != null)
	{
		var st = fMesAnio
		var anio = st.substring(st.indexOf('-', 0)+1, st.length)
		var mes = st.substring(0, st.indexOf('-', 0))
		
		var ds = databaseManager.createEmptyDataSet( 0,  new Array('plan','importe_debe','importe_haber','saldo_deudor','saldo_acreedor','codigo'))
		var tipos = new Array (JSColumn.TEXT,JSColumn.NUMBER,JSColumn.NUMBER,JSColumn.NUMBER,JSColumn.NUMBER,JSColumn.TEXT)
		var ejercicio
		var fs = databaseManager.getFoundSet('infocom','rel_asiento_ejer_mes')
		fs.loadAllRecords()
		fs.find()
		
		fs.año = anio 
		fs.mes = '<=' + mes

		fs.newRecord()
		fs.año = anio -1
		
		var cant = fs.search()
		if (cant != 0)
		{	
			fs.sort('plan_id asc')
			fs.setSelectedIndex(1)
			var i = 1
			while (i <= cant)
			{
				var plan = fs.plan_id
				var saldo = 0
				var sum_deud = 0
				var sum_acree = 0
				while ((plan == fs.plan_id)&&(i<= cant))
				{
					fs.setSelectedIndex(i)
					sum_deud += fs.sum_deud_mes
					sum_acree += fs.sum_acree_mes
					saldo+= fs.saldo
					i++
				}
				if (saldo <0)
					var fila = new Array(fs.rel_asiento_ejer_mes_to_plan_de_cuentas.sinonimo,sum_deud,sum_acree,null,saldo,fs.codigo_format)
				else
					var fila = new Array(fs.rel_asiento_ejer_mes_to_plan_de_cuentas.sinonimo,sum_deud,sum_acree,saldo,null,fs.codigo_format)
				ds.addRow(fila)	
			}
			var data = ds.createDataSource('balance',tipos)
			var frm = solutionModel.newForm( 'balance_2',  data,  null, false,  640, 640)
			frm.view = JSForm.LOCKED_TABLE_VIEW
			ds.sort('codigo','asc')
			for (var i = 1; i<=ds.getMaxColumnIndex(); i++)
			{
				var f = frm.newField(ds.getColumnName(i),JSField.TEXT_FIELD, 0+100*i, 41, 100, 20)
				f.titleText = ds.getColumnName(i)
				f.anchors = SM_ANCHOR.EAST | SM_ANCHOR.WEST
			}
			frm.newTitleHeaderPart(40)
			
			var titulo = 'Balance Hasta Fecha: ' + mes + ' - ' + anio
			var lbl = frm.newLabel(titulo,100,0,500,30)
			lbl.fontType = 'Tahoma,bold,18'
			
			application.showFormInDialog(forms.balance_2,null,null,null,null,'Balance',true,false,'balance',false)
		}
		else
			globals.gDialog('Error','No se encontraron datos para ese mes y año','OK','CerrarForm')
	}
	else
		globals.gDialog('Error','Por favor, elija un mes y año','OK','CerrarForm')
}
